You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
adjacent pixel before and after encryption
5 views (last 30 days)
Show older comments
- I wonder if my result of the adjacent pixel is correct before and after encryption for vertical, horizontal. I'm also including the histograms of my encryption image, with the image results.
17 Comments
Image Analyst
on 31 Dec 2020
None of those images display in my Firefox browser.
I have no idea what the correctly encrytped value would be in any pixel. Besides, we're not allowed to discuss encryption in this forum.
I suggest you just follow normal debugging procedures like setting breakpoints, stepping through line-by-line, examining variable values in the workspace panel, etc. I mean, you can probably do that with your code better than we can.
assaad el makhloufi
on 31 Dec 2020
Image Analyst thanks for your reply, I have just uploaded the images. My question was not about the value of the pixel or if the encryption is correct, I just wondered if my adjacent pixel from the original and from the encrypted is correct.
Walter Roberson
on 31 Dec 2020
We wouldn't know -- we do not have the original image.
assaad el makhloufi
on 31 Dec 2020
Walter Roberson thank you four your reply, i just upload the histogram of the original image , as the image show the level of the gray image is concentrating in 80 and 200-256 . I didnt understand the meaning of the corrupt .
Walter Roberson
on 31 Dec 2020
Firefox cannot display the image I indicated - though it appears that MacOS "Preview" can display it.
You had already uploaded Original image histo.jpg -- it is the original image itself that we do not have.
assaad el makhloufi
on 31 Dec 2020
Walter Roberson, i have uploaded the original image.
Image Analyst
on 31 Dec 2020
OK the images display now.
OK, let's take an arbitrary pixel at (row, column) = (2,2). Now, what do you consider the "adjacent" pixels? The 8 neighboring pixels at (1,2), (1,2), (1,3), (2,1), (2,3), (3,1), (3,2), and (3,3)? Ok, let's assume those 8 neighboring pixels are the pixels "adjacent" to the pixel at (2,2). And of course, we'll have 3 images I presume:
- the original image
- the encrypted image (IF it's even in a rectangular (row, column) format), and
- the decrypted image (which should match the original image).
Now exactly what comparisons do you want to do between the 8 adjacent pixels and a pixel at a given location among the 3 images (9*3=27 pixels in total, times the number of pixels in the image, like a million or whatever)?
I'd say your encryption/decryption algorithm is correct is a round trip gives you the original image exactly.
assaad el makhloufi
on 31 Dec 2020
Edited: assaad el makhloufi
on 31 Dec 2020
Image Analyst thanks for your reply , i need to show the adjacent pixel ( Horizontal and verticale) for the original image and for the encryption image .
In other way : Relationship between neighboring pixels in horizontal , vertical
The images that i uploaded for the adjacent pixel ( Horizontal and verticale) was calculated by
function r_xy=AdjancyCorrPixel( P )
P=imread('C:\Users\hp\Desktop\orig.PNG');
x1 = double(P(1:end-1,1:end-1,1));
y1 = double(P(2:end,2:end,1));
randIndex1 = randperm(numel(x1));
randIndex1 = randIndex1(1:5000);
x = x1(randIndex1);
y = y1(randIndex1);
r_xy = corrcoef(x,y);
scatter(x,y);
xlabel('Pixel gray value on location (x,y)')
ylabel('Pixel gray value on location (x+1,y)')
end
- But i dont know if this is the correct method to display the adjacent pixel .
Walter Roberson
on 31 Dec 2020
P = imread('orig.PNG');
if ndims(P) > 2; P = rgb2gray(P); end
hadj = accumarray(1+[reshape(P(:,1:end-1),[],1), reshape(P(:,2:end),[],1)], 1, [256,256]);
hver = accumarray(1+[reshape(P(1:end-1,:),[],1), reshape(P(2:end,:),[],1)], 1, [256,256]);
subplot(2,1,1)
surf(hadj, 'edgecolor', 'none')
title('horizontal')
subplot(2,1,2)
surf(hver, 'edgecolor', 'none')
title('vertical')
This has a slight bias: it counts from one pixel to the next one with higher index, but it does not count from higher index to lower. For example if the last column was the only column that had pixel value 99, then you would get 99's on the y axes, but would not get any 99 on the x axes.
assaad el makhloufi
on 31 Dec 2020
Walter Roberson thanks very much for your demonstration, just to clear my idea; I want to display the adjacent pixel (vertical and horizontal) like the image that I upload now Example.jpg
Image Analyst
on 31 Dec 2020
Are you by chance really after the GLCM, but just didn't know the name of it?? That's the gray level cooccurrence matrix. If so, see attached demo.
Because I don't see any encryption going on, like DES or whatever.
Walter Roberson
on 1 Jan 2021
The resolution of example.JPG is too low for me to read.
assaad el makhloufi
on 1 Jan 2021
Image Analyst thank you verry much for your demonstration as wel as Walter Roberson , for the GLCM if find it verry intresting and i have just working with this demo and i uploaded the image results but i didint understand verry much .
- In the other hand i have a question , i have a text file ( binary number) and i want to read this file as image but the range of the element is verry big , and i want to set this value between 0-256 .
Image Analyst
on 1 Jan 2021
You should never us jpg images for image analysis. Your image looks like it should be an image with only 2 gray levels. You wouldn't use GLCM on a binary image since it's rather meaningless. It's meant for gray scale images. You have a gray scale image because you mistakenly used a JPG image, so in stead of just the 2 gray levels like you expect, you have alots of gray levels due to JPG being a lossy compression method and it changing the gray levels. And you can see that in the GLCM. Instead of just signal at two points representing the two gray levels, you have a cluster of points representing differences between each pixel and its adjacent neighbors. These differences are not all 1 or zero like they'd be with a binary image.
But anyway, that was jsut a guess because I can't really figure out what you're after when you ask "if my result of the adjacent pixel is correct before and after encryption for vertical, horizontal" Still not sure what you mean by encryption, adjacent, and correct.
assaad el makhloufi
on 1 Jan 2021
Image Analyst thank you for this important idea and demonstration, so do i should to use .png image because my images as you see there is only two level grey and i need to se the adjacent pixel
Walter Roberson
on 1 Jan 2021
Yes, use png or bmp images.
Image Analyst
on 1 Jan 2021
Yes, in general, but then like I said you wouldn't use GLCM I don't think, but maybe you would. Try it and see. But with a binary image like you have the difference between adjacent pixels will always be 0 or some other single number (the gray level difference). Still not sure what you're after because you didn't explain any of me questions in the last paragraph.
Answers (1)
assaad el makhloufi
on 1 Jan 2021
For bmp and png they give the same results . I have need to plot this 3 type of adjacent pixel for my image ( image is generated by envi software map) .
1- histograme of orig image (map)
2- adjacent pixel for orig image( vertical, horizon, diagonal)
3-histograme of encrypted image ( the encryption image was generated by vhdl with text file) , for that i need to converted to encrypted image and display the histogram
4-adjacent pixel for encryption image( vertical, horizon, diagonal)
5- Comparaison between orig and encrypted image.
6 Comments
Walter Roberson
on 1 Jan 2021
Go ahead. I already showed you how to calculate the horizontal and vertical counts in https://www.mathworks.com/matlabcentral/answers/706173-adjacent-pixel-before-and-after-encryption#comment_1238098 . It is not difficult to adjust that for diagonal as well.
assaad el makhloufi
on 1 Jan 2021
I have upload the result image vert-horiz from your code , but i didnt understand how i can
interpreter this results .
Walter Roberson
on 2 Jan 2021
On one axis you have the 256 different grayscale levels as the first element of the pair of pixels. On a second axis you have the 256 different grayscale levels as the second element of the pair of pixels. Now you say that you want a histogram. Histograms involve counts of the number of times circumstances occur, and representing the counts as a dimension. So you have 3 dimensions: source grayscale, destination grayscale, and counts. That requires a 3d graph, not a 2d graph. The plots you show are scatter plots, not histograms, and show only whether a combination occurs, with no information about how often it occurs.
You need to make a decision: do you want histograms like you asked for, or do you want scatter plots like your sample images? Or you could scatter but represent the count as color.
assaad el makhloufi
on 2 Jan 2021
Edited: assaad el makhloufi
on 2 Jan 2021
thankyou verry much for this demonstration , in your opinion wath is the best solution for my case considering that my image has just two level gray .
Image Analyst
on 2 Jan 2021
If you really want to know how many times graylevel1 occurs next to graylevel2, in each direction, then you can use graycomatrix(), like the attached example.
assaad el makhloufi
on 2 Jan 2021
thankyou verry much for both of you for this explication and idea , i will go throught this direction.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)