How to remove the lines in the image?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tham Wei Jian
am 15 Aug. 2019
Bearbeitet: Sourav Bairagya
am 19 Aug. 2019
Here is my coding, can anyone help me edit my coding to remove the lines inside the image?This is very annoying >.<
I'm actually converted from the text file.
The image should be 224x224x3
The text file is 1x150528
==============================================
OUTPUT:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/234041/image.png)
===============================================
fid = fopen('output_data_1.txt','r');
img = fscanf(fid,'%x');
fclose(fid);
outImg = reshape(img,[224*1 224*3]);
outImg = outImg';
imshow(outImg,[])
==================================================
2 Kommentare
KALYAN ACHARJYA
am 15 Aug. 2019
Bearbeitet: KALYAN ACHARJYA
am 15 Aug. 2019
Which lines? If you do sort of operation on lines pattern, then image may turn dark gray image.??
Remove lines from the image, then fill the vacant location by??
Geoff Hayes
am 15 Aug. 2019
Tham - please don't post duplicate questions. This is a continuation of your https://www.mathworks.com/matlabcentral/answers/476273-how-to-convert-1-column-vector-text-file-to-rgb-image where the problem is due to the outImg being reshaped incorrectly. According to your initial post, the image should be 224x224x3. In the above, you have created a 224x672 image.
Akzeptierte Antwort
Sourav Bairagya
am 19 Aug. 2019
Bearbeitet: Sourav Bairagya
am 19 Aug. 2019
After inspecting the script that you are using, it seems that data stored in the “input_data.txt” is stored in channels first format. Instead of reshaping the data into 224X672 image, you should reshape it into 3X224X224 image.
Now, to display the image using “imshow”, the input file must be of size MXNX3. Hence, in this case, desired dimension is 224X224X3.
To get that desired dimension one option is to extract all the channels separately, and then concatenate them in order to get back the actual image. Make sure that the datatype of image data is of “uint8”.
Another option is to use “permute” function, in which it is possible to re-arrange the dimensions as per desired order.
Finally, the image which is obtained is a transposed version of the original one. To get back the actual image, you should use the “permute” function again to transpose it.
The whole code is as follows:
fid = fopen('input_data.txt','r');
img = fscanf(fid,'%d');
fclose(fid);
outImg = uint8(reshape(img,[3 224 224]));
outImg1=uint8(reshape(outImg(1,:,:),[224,224])); %Extracting the channels separately
outImg2=uint8(reshape(outImg(2,:,:),[224,224]));
outImg3=uint8(reshape(outImg(3,:,:),[224,224]));
RGB = cat(3,outImg1,outImg2,outImg3); %Concatenation of all the channels
%RGB = permute(outImg,[2 3 1]); %Instead of using above four lines, you
%Can also use this line to reshape the data
%in 224X224X3 i.e. channels last format.
RGB = permute(RGB,[2 1 3]); %This is to transpose the color image
imshow(RGB,[]);
Actual image has 3 channels and of the size 224X224X3 and in your code the output image was of size 224X672. As you were merging independent pixel data from all the 3 channels in 2nd dimension, hence those undesired lines were turning up in the output image due to overlap of all those different channel data.
To know more information about “permute” function and “imshow” function follow these links:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Import, Export, and Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!